package com.csap.framework.oauth2.server;

import cn.dev33.satoken.oauth2.logic.SaOAuth2Template;
import cn.dev33.satoken.oauth2.model.SaClientModel;
import com.csap.framework.oauth2.server.service.ClientService;
import com.csap.framework.oauth2.server.service.PlatformService;
import com.csap.framework.oauth2.server.service.UserOpenInfoService;
import lombok.AllArgsConstructor;

/**
 * Sa-Token OAuth2.0 整合实现
 *
 * @author ycf
 */
@AllArgsConstructor
public class SaOauth2TemplateImpl extends SaOAuth2Template {
    private ClientService clientService;
    private UserOpenInfoService userOpenInfoService;
    private PlatformService platformService;

    @Override
    public String getPlatform(String platform) {
        return platformService.findByCode(platform).getPlatform();
    }

    @Override
    public SaClientModel getClientModel(String clientId) {
        return clientService.getClientModel(clientId).transform(SaClientModel.class);
    }

    @Override
    public SaClientModel getCheckClientModel(String clientId) {
        return clientService.getCheckClientModel(clientId).transform(SaClientModel.class);
    }

    @Override
    public String getOpenid(String clientId, Object loginId) {
        return userOpenInfoService.getOpenId(clientId, loginId.toString());
    }
}
